<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class AllTopic_widget extends MY_Widget {
  function __construct(){
    parent::__construct();
  }

  function run(){
    if($HTML = $this->cache->get("alltopic_widget_html")){
      return $HTML;
    }
    $this->load->model("forum_model","forumModel");
    $this->load->model("images_model","imagesModel");
    $where["where"]["status"] = 1;
    //$where["where_not_in"]["cat_id"] = array(4,5);
    $where["limit"] = 10;
    $listpost = $this->forumModel->get($where);
    if(!empty($listpost)){
      foreach ($listpost as $key => $value) {
        $whereImage["where"]["pos_id"] = $value["id"];
        $whereImage["order"] = "id ASC";
        $images = $this->imagesModel->get($whereImage);
        $listpost[$key]["images"] = $images;
      }
      $this->_assign("listpost",$listpost);
    }
    $HTML = $this->_fetch("alltopic");
    $this->cache->write($HTML,"alltopic_widget_html");
    return $HTML;
  }
}